import {
  Injectable
}
from 'angular2/core';
import {
    Http
} from 'angular2/http';
import {
    PItem,
    BResult
} from './app.model';

@Injectable()
export class Util{
    constructor(public http:Http){}
    
    getAV(input:string):any{
        var reg = /av(\d+)/g;
        var ss =input.split('/');
        var id:any = 0;
        for(var i in ss){
            var s = ss[i];
            if(reg.test(s))
                return s.replace(reg,'$1');
        }
        return id;
    };
    
    getVideos(aid,cb:(result:BResult)=>void):void{
        var cidrequrl = 'http://www.bilibilijj.com/Api/AvToCid/' + aid;
        
        this.http.get(cidrequrl).map(res => <BResult>res.json())
            .subscribe(result => cb(result),
                error => console.log('error',error));
    }
}